-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add BindGroupLayout caching via descriptors #21205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
crates/bevy_anti_alias/src/contrast_adaptive_sharpening/node.rs
Outdated
Show resolved
Hide resolved
|
Can you add more motivation to the PR description please? I'm having trouble following why this is a good idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work. Thanks for doing all this. I'd like to see some benchmarking as I'm a little worried about performance. However, my intuition is that we are extremely read heavy and so it feels likely that we can work around any performance issues if they come up. I can help with benchmarking if necessary. But overall the code looks great!
| #[derive(Clone, Debug, PartialEq, Eq, Hash, Default)] | ||
| pub struct BindGroupLayoutDescriptor { | ||
| /// Debug label of the bind group layout descriptor. This will show up in graphics debuggers for easy identification. | ||
| pub label: Option<Cow<'static, str>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as an aside, I kinda feel like we should make labels non-optional in all our code but that's for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this would be a good follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using the same DebugName strategy that ECS uses for system names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can help with benchmarking if necessary
@tychedelia I would definitely appreciate that (especially if you can explain how)
| #[derive(Resource)] | ||
| pub struct PipelineCache { | ||
| layout_cache: Arc<Mutex<LayoutCache>>, | ||
| bindgroup_layout_cache: Arc<Mutex<BindGroupLayoutCache>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see benchmarking before any changes but this might be a rare scenario RwLock could win. Or maybe even something like dashmap. Anyway, just curious how much contention there actually is on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might get wins doing this on the layout_cache too. I thinkt he shader_cache probably wouldnt see any significant wins from it but might as well be consistent if we switch to RwLock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a migration guide Zeophlite#4
| #[expect(clippy::option_map_or_none, reason = "TODO")] | ||
| label: Self::label().map_or(None, |f| Some(f.into())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #[expect(clippy::option_map_or_none, reason = "TODO")] | |
| label: Self::label().map_or(None, |f| Some(f.into())), | |
| label: Self::label().map(|f| f.into()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm once the clippy lint is addressed.
This will be very helpful for an upcoming PR I'm working on to simplify render boilerplate. I'd also like if we could extend this to cache the actual pipelines.
| #[expect(clippy::redundant_closure_for_method_calls, reason = "TODO")] | ||
| descriptor.label.as_ref().map(|s| s.as_ref()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #[expect(clippy::redundant_closure_for_method_calls, reason = "TODO")] | |
| descriptor.label.as_ref().map(|s| s.as_ref()), | |
| descriptor.label.as_ref().map(Cow::as_ref), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting in the work for this!
Approved, contingent on my two suggestions and the migration guide being merged.
I will make a follow-up PR for AsBindGroup cleanups to remove the RenderDevice dependency from it.
# Objective - Defer creating `BindGroupLayout` by using a `BindGroupLayoutDescriptor` and cache the results - Unblocks `bevy_material` (render-less material definitions) - Blocked by bevyengine#21533 ## Solution - Reviewers, look at first commit for mechanism, and following for usage ## Testing - CI --------- Co-authored-by: atlas <[email protected]>
* Fix compile error when compiling with DLSS enabled after #21205 * Use permutation sampling for ReSTIR DI temporal reuse to fix artifacts under DLSS-RR * For both DI and GI, removed the spatial raytrace, and moved it to the final reservoir before shading. * Reduced DI initial samples 32 -> 8 for better performance at the cost of quality * Various specular GI improvements and bugfixes (still kinda terrible overall, I need to do some research on how people usually do this kind of thing) * Made the world cache adapt faster / be less stable * Switched spatial hashing collisions from to linear probing --------- Co-authored-by: Jasmine Schweitzer <[email protected]>
Objective
BindGroupLayoutby using aBindGroupLayoutDescriptorand cache the resultsbevy_material(render-less material definitions)Solution
Testing